<template>
  <div class="tabs">
    <el-tag
      :key="tag.path"
      v-for="tag in tags"
      :effect="$route.name === tag.name ? 'dark' : 'plain'"
      @click="changeMenu(tag)"
      :closable="tag.name !== 'home'"
      :disable-transitions="false"
      @close="handleClose(tag)"
    >
      {{ tag.label }}
    </el-tag>
  </div>
</template>

<script>
import { mapState, mapMutations } from 'vuex'
export default {
  computed: {
    ...mapState({
      tags: (state) => state.tab.tabList,
      currentMenu: (state) => (state.tab.currentMenu.type = 'success'),
    }),
  },
  data() {
    return {
      currentType: '',
    }
  },
  methods: {
    ...mapMutations(['closeTab']),
    handleClose(tag) {
      this.closeTab(tag)
    },
    changeMenu(val) {
      if (this.$router.currentRoute.fullPath !== val.path) {
        this.$router.push({ name: val.name })
      }
      this.$store.commit('selectMenu', val)
    },
  },
}
</script>

<style lang="scss" scoped>
.tabs {
  margin: 20px;
  .el-tag {
    margin-right: 15px;
    cursor: pointer;
  }
}
</style>
